package com.hclc.entity.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 菜单权限类型
 *
 * @author yurj
 * @version 1.0
 * @mail 1638234804@qq.com
 * @date 2020/8/23 15:06
 */
public enum PermTypeEnum implements IEnum<Integer> {


    ALL(1, "全部"),


    SECTION(0, "部分");


    @JsonValue
    @EnumValue
    private final int code;


    private final String desc;

    PermTypeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public Integer getValue() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static PermTypeEnum find(String desc) throws IllegalArgumentException {
        for (PermTypeEnum model : PermTypeEnum.values()) {
            if (model.getDesc().equals(desc)) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }

    @JsonCreator
    public static PermTypeEnum find(int code) throws IllegalArgumentException {
        for (PermTypeEnum model : PermTypeEnum.values()) {
            if (model.getValue() == code) {
                return model;
            }
        }
        throw new IllegalArgumentException();
    }
}
